Add test for va_copy presents. Break build if not available.
authoroliskoli <oliskoli>
Thu, 23 Nov 2006 00:49:54 +0000 (00:49 +0000)
committeroliskoli <oliskoli>
Thu, 23 Nov 2006 00:49:54 +0000 (00:49 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index 3c2d5ad9337d0b41ed224f28a2b0cfa68dd0d0fa..daa85fef4c7325b9ea373363ea48145ba0da25a7 100644 (file)
--- a/defs.h
+++ b/defs.h
 #  define _CRT_SECURE_NO_DEPRECATE 1
 #endif
 
+/* va_copy workaround */
+
+#ifndef va_copy
+#  ifdef __va_copy
+#    define va_copy __va_copy
+#  else
+#    error Function 'va_copy' or '__va_copy' is not defined in your environment!
+#    error Please mail some information about your system 
+#    error (platform,compiler,...) to gpsbabel-code@lists.sourceforge.net
+#  endif
+#endif
+
 /* Pathname separator character */
 #if __WIN32__
 #  define GB_PATHSEP '\\'
diff --git a/util.c b/util.c
index 9fa0214596445da910c8bb524df6845a2bc7b141..34d61e2bf7856d0d9e4fc39139454faa6ecb2268 100644 (file)
--- a/util.c
+++ b/util.c
@@ -301,6 +301,7 @@ xvasprintf(char **strp, const char *fmt, va_list args)
        char *newbuf;
        size_t nextsize = 0;
        int outsize;
+       va_list tmp;
 
        bufsize = 0;
        for (;;) {
@@ -309,7 +310,7 @@ xvasprintf(char **strp, const char *fmt, va_list args)
                                *strp = NULL;
                                return -1;
                        }
-                       bufsize = 1;
+                       bufsize = FIRSTSIZE;
                } else if ((newbuf = xrealloc(buf, nextsize)) != NULL) {
                        buf = newbuf;
                        bufsize = nextsize;
@@ -319,8 +320,10 @@ xvasprintf(char **strp, const char *fmt, va_list args)
                        return -1;
                }
 
-               outsize = vsnprintf(buf, bufsize, fmt, args);
-
+               va_copy(tmp, args);
+               outsize = vsnprintf(buf, bufsize, fmt, tmp);
+               va_end(tmp);
+               
                if (outsize == -1) {
                        /* Clear indication that output was truncated, but no
                         * clear indication of how big buffer needs to be, so